//级别筛选
var level = null;
var orderBy = null;
$('.leftShaiXuan').on('click',function(){
	if($(this).attr("hide") == "true"){
		$('#firstPopover').show();
		$('#secondPopover').hide();
		$(this).attr("hide","false")
		$('.rightShaiXuan').attr("hide","true")
	}else{
		$('#firstPopover').hide();
		$(this).attr("hide","true")
	}
})
console.log($('.leftShaiXuan'));
//级别筛选
$('.rightShaiXuan').on('click',function(){
	if($(this).attr("hide") == "true"){
		$('#secondPopover').show();
		$('#firstPopover').hide();
		$('.leftShaiXuan').attr("hide","true")
		$(this).attr("hide","false")
	}else{
		$('#secondPopover').hide();
		$(this).attr("hide","true")
	}
})
/*
//级别筛选后分销商列表
$('#firstPopover').find('li').on('click',function(){
	$(this).find('ul').show();
	$(this).siblings().find('ul').hide();
})*/

//选择级别获得数据
$('#firstPopover').find('ul li').on('click',function(){
	var _this = $(this);
	$('#firstPopover').hide();
	$('.leftShaiXuan').find('b').html($(this).html());
	//var status = $('.rightShaiXuan').find('b').html();
	//$('#secondPopover').hide();
	//$('.rightShaiXuan').attr("hide","true");
	$('.leftShaiXuan').attr("hide","true");
	level = $(this).attr("level");
	getDistributorAjax(level,null);
	console.log('click');
})

//商品状态筛选后商品列表
$('#secondPopover').find('ul li').on('click',function(){
	var _this = $(this);
	$('#firstPopover').hide();
	$('#secondPopover').hide();
	$('.rightShaiXuan').find('b').html(_this.html());
	$('.leftShaiXuan').find('b').html("级别");
	orderBy = $(this).attr("orderBy");
	$('#secondPopover').hide();
	$('.rightShaiXuan').attr("hide","true");
	$('#firstPopover').hide();
	$('.leftShaiXuan').attr("hide","true");
//	alert(orderBy);
	getDistributorAjax(null,orderBy);
})

//筛选分销商ajax
function getDistributorAjax(level,orderBy){
	console.log('ajax');
	$.ajax({
		type:"POST",
		url : "/weishang/distributor/distributorListMore.htm",
		dataType : "html",
		data : {
			"level" :level,
			"orderBy" :orderBy
		},
		success : function(data) {
			$('.distributorWrap').html(data);
		}
	})
}
/*---------------------------上拉加载更多-------------------------------*/
(function($) {
	//页面a标签的点击跳转事件
	mui('#pullrefresh').on('tap', 'a', function (e) {
		if (!this.classList.contains('mui-disabled')) {
		mui.openWindow({
		url: this.getAttribute('href'),
		id: 'info'
		});
		}
		else {
		mui.preventDefault(e);
		mui.stopPropagation(e);
	}
	});
})(mui);

mui.init({
  pullRefresh : {
    container:'#pullrefresh',//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
    up : {
      height:50,//可选.默认50.触发上拉加载拖动距离
      auto:true,//可选,默认false.自动上拉加载一次
      contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
      contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
      callback: function() {
				var self = this;
				var dataStatus = false;
				var index = document.querySelector('.mui-table-view').getAttribute('index');
				var numObj = document.querySelector('#pageNum');
				var ul = document.querySelector('.dataWrap');
				var my = document.createElement('my');
				var loadMore = document.querySelector('.mui-pull-loading');
				$.ajax({
					url:'/weishang/distributor/distributorListMore.htm',
					type:'get',
					dataType:'html',
					data : {
						"level" :level,
						"orderBy" :orderBy,
						'pageNo':numObj.value
					},
					success:function(data){
						if(!(data.replace(/(^\s*)|(\s*$)/g,"") == '')){
							numObj.value = numObj.value -(-1);
							my.innerHTML = data;
							ul.appendChild(my);
						}else{
							dataStatus = true;
							loadMore.innerHTML = '没有更多数据了';
						}
					}
				});
				self.endPullupToRefresh(dataStatus);
			}
    }
  }
});